package com.tanhua.mqlistener;

import com.tanhua.dao.LogMapper;
import com.tanhua.domain.Log;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@RocketMQMessageListener(
        topic = "tanhua-log",
        consumerGroup="tanhua-c"
)
@Component
public class LogListener implements RocketMQListener<Map> {

    @Autowired
    private LogMapper logMapper;


    @Override  //队列中有数据 该方法就执行
    public void onMessage(Map map) {

        System.out.println("监听到了tanhua-log队列，开始实现了...");
        //实现内容
        Integer userId=Integer.parseInt(map.get("userId").toString());
        String type =(String)map.get("type");
        String logTime =(String)map.get("logTime");


        //往数据库做插入
        Log log = new Log();
        log.setUserId(userId.longValue());
        log.setType(type);
        log.setLogTime(logTime);


        logMapper.insert(log);

    }
}
